#include <bits/stdc++.h>
using namespace std;
int main() {
    int n,m;
    cin >> n >> m;
    pair<double,double> v[n+1];
    int a;
    double b;
    v[0]=make_pair(1.0,0);
    for (int i=1;i<=n;i++)
    {
        cin >> a >> b;
        if (a==1)
        {
            v[i]={v[i-1].first*b,v[i-1].second};
        }else
        {
            v[i]={v[i-1].first,v[i-1].second+b};
        }
    }
    int l,r;
    double x,y;
    for (int i = 0; i < m; i++) {
        cin>>l>>r>>x>>y;
        double k=v[r].first/v[l-1].first;
        double sita=v[r].second-v[l-1].second;
        x=x*k;
        y=y*k;
        double tempx=x,tempy=y;
        x=tempx*cos(sita)-tempy*sin(sita);
        y=tempx*sin(sita)+tempy*cos(sita);
        cout << fixed << setprecision(3);
        cout<<x<<" "<<y<<endl;
    }
    return 0;
}
